package 力扣._215_数组中的第K个最大元素;

import java.util.PriorityQueue;

public class Solution {
    public int findKthLargest(int[] nums, int k) {
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        int count = 0;
        for (int i = 0; i < k; i++) {
            queue.add(nums[count++]);
        }
        while (count < nums.length) {
            int poll = queue.peek();
            if(poll<nums[count]){
                queue.poll();
                queue.add(nums[count]);
            }
            count++;
        }
        return queue.poll();
    }
}
